/********************************************************************

Write Date: 2015/04/14
Author: Apple
>>>> Implement Class _ObjectCreateHelper.
	
Modify Date: 2015/08/13
Author: Apple
>>>> Add the ability to record the name of newing Objects.

*********************************************************************/
#include "_ObjectCreateHelper.h"
#include <assert.h>
#include <QThread>



_NS_OOP_BEGIN



_ObjectCreateHelper::_ObjectCreateHelper ()
{

}



void
_ObjectCreateHelper::recordNewingObject (const QString& r_name)
{
	auto tid = QThread::currentThreadId ();
	_mutex.lock ();
	assert (!_map_ObjsNewing.contains (tid));
	_map_ObjsNewing[tid] = r_name;
	_mutex.unlock ();
}



void
OOP::_ObjectCreateHelper::recordNewingObjectFinished ()
{
	auto tid = QThread::currentThreadId ();
	_mutex.lock ();
	_map_ObjsNewing.remove (tid);
	_mutex.unlock ();
}



bool
_ObjectCreateHelper::isNewingObject () const
{
	auto tid = QThread::currentThreadId ();
	_mutex.lock ();
	bool isCreateOnHeap = _map_ObjsNewing.contains (tid);
	_mutex.unlock ();
	return isCreateOnHeap;
}



QString
_ObjectCreateHelper::nameOfNewingObject () const
{
	QString name;
	auto tid = QThread::currentThreadId ();
	_mutex.lock ();
	auto it_result = _map_ObjsNewing.find (tid);
	if (it_result == _map_ObjsNewing.end ())
		name = "";
	else
		name = *it_result;
	_mutex.unlock ();
	return name;
}



_NS_OOP_END